package kz.simplex.photobox.ui;

import java.io.File;

import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.faces.model.SelectItem;

import kz.simplex.photobox.model.Sex;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.richfaces.event.UploadEvent;
import org.richfaces.model.UploadItem;

@Stateful
@Name("userPreference")
@Scope(ScopeType.EVENT)
public class UserPreference implements IUserPreference {
	
	@In(required=false, scope=ScopeType.CONVERSATION)
	@Out(required=false, scope=ScopeType.CONVERSATION)
	private File avatarData;
	
	static final SelectItem[] sexs = new SelectItem[] {
		new SelectItem(Sex.MALE, "Male"),
		new SelectItem(Sex.FEMALE, "Female")
	};
	
	public SelectItem[] getSexs() {
		return sexs;
	}
	                                                
	
	public void uploadAvatar(UploadEvent event) {
		UploadItem item = event.getUploadItem();	
		avatarData = item.getFile();
	}
	
	public File getAvatarData() {
		return this.avatarData;
	}
	public void setAvatarData(File avatarData) {
		this.avatarData = avatarData;
	}
	
	@Remove
	public void destroy() {}
}
